<?php
//include_once( "../sql/sqlCon.php" );
$refPage = "newsCMS.php";
include( "langincluder.php" );

$sessionUserLevelName = "userLevel";

$newsperpage=10;


$pagenum = isset($_GET['pnum']) ? (int)$_GET['pnum'] : 0;
$quer = mysql_query("SELECT line FROM $newsCMSTableName");
$newsnum = mysql_num_rows($quer);

$startpoint=$newsnum-$pagenum*$newsperpage;
$endpoint=$startpoint-$newsperpage;

if($startpoint<0) echo $strings['pageUnavailable'];
else
{

// load the requested news in the arrays
if($endpoint<0) $endpoint=0;
$entries=$startpoint-$endpoint;

$titles=array();
$contents=array();
$postedOnArray=array();
$discussLinksArray=array();

$quer=mysql_query("SELECT * FROM $newsCMSTableName WHERE line<='$startpoint' AND line>='$endpoint' ORDER BY line");
for($i=0; $newsContent=mysql_fetch_array($quer); $i++)
{
	$titles[$i] = $newsContent['title'];
	$contents[$i] = $newsContent['content'];
	$postedOnArray[$i] = $newsContent['postedon'];
	$discussLinksArray[$i] = $newsContent['discussl'];
}




if(isset($_GET['pnum']) && $_GET['pnum']>0 ) echo $_strings['page']." ".($_GET['pnum']+1);

for($i=$entries-1; $i>=0; $i--)
{
	if( !empty($discussLinksArray[$i]) ) 
		 $currentDiscussLink = "<a href='".$discussLinksArray[$i]."'>".$strings['linkMoreInfoHere']."</a>";
	else $currentDiscussLink = $strings['noLink'] ;

	if( isset( $_SESSION[$sessionUserLevelName] ) && $_SESSION[$sessionUserLevelName]==1) 
		 $editer = "<span class='entryEdit'> 
					 <a href='index.php?p=602&lid=$i'>[ ".$strings['adminEditLink']." ]</a>&nbsp;&nbsp;
		             <a href='index.php?p=7&action=delete&logid=$i'>[ ".$strings['adminDeleteLink']." ]</a>
					</span>";
	else $editer = "";


	echo "<div class='entry'><span class='entryTitle'>".$titles[$i]."</span><span class='entryDate'>".$postedOnArray[$i]."</span>$editer
      <div class='entryContent'>".($htmlAllowed ? htmlspecialchars_decode($contents[$i]) : $contents[$i])."</div>
	  <div class='entryLink'>$currentDiscussLink</div></div>";
}


echo '<br>';
// to be redone
for($i=0; $i<ceil($newsnum/$newsperpage); $i++) echo '<a href="index.php?pnum='.$i.'"><button type="button">'.($i+1).'</button></a>&nbsp ';


if( isset($_SESSION[$sessionUserLevelName]) && $_SESSION[$sessionUserLevelName]==1) echo "<a href='index.php?p=601'>".$strings['adminCreateNew']."</a>";

}
?>